
const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  }
}

module.exports = [
  // user login
  {
    url: '/vue-element-admin/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: 'Account and password are incorrect.'
        }
      }

      return {
        code: 20000,
        data: token
      }
    }
  },
  {
     url: '/api/user/login',
     type: 'post',
     response: config => {
      const { name, password } = config.body
      // const token = tokens[username]
      // // mock error
      // if (!token) {
      //   return {
      //     code: 60204,
      //     message: 'Account and password are incorrect.'
      //   }
      // }
      if (!(name == 'admin' &&  password == '123456')) return {
        code: '1',
        message: '失败，账号或密码错误',
        data: ''
      }
      return {
        "code": "0",
        "status": "ok",
        "message": "成功",
        "serverTime": 123123123123123,
        "data": {
          "token": "",
          "name": "",
          "phone": "",
          "status": 1,
          "loginTime": 123123123,
          "num": 0,
          "company": { //买家信息
            "name": "",
            "province": {
              "id": 1,
              "name": "浙江省"
            },
            "city": { //城市
              "id": 1,
              "name": "杭州市"
            },
            "area": { //区县
              "id": 1,
              "name": "西湖区"
            },
            "town": { //街道
              "id": 1,
              "name": "北山街道"
            },
            "address": "",
            "phone": "", //手机号
            "contacts": "", //公司联系人
            "mobile": "", //公司联系人电话
            "oranizingCode": "" //组织机构代码
      
          },
      
          "salesCompany": {
            "name": "",
            "oranizingCode": ""
      
          },
          "gorups": [{
            "id": 2,
            "name": "买家",
            "store": 1
          }]
      
      
        }
      
      }
    }
  },
  // get user info
  {
    url: '/vue-element-admin/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 50008,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 20000,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/vue-element-admin/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
